<template>
  <div class="flex-grow-1 container-p-y user-profile" :class="[layout]">
    <div class="nav-align-top">
      <ul class="nav nav-pills flex-column flex-md-row mb-6 gap-2 gap-lg-0">
        <li class="nav-item"><a class="nav-link waves-effect waves-light" :class="[tab == 1 ? 'active' : '']"
            @click="tab = 1"><i class="ti-xs ti ti-users me-1"></i> Account</a></li>
        <li class="nav-item"><a class="nav-link waves-effect waves-light" :class="[tab == 2 ? 'active' : '']"
            @click="tab = 2"><i class="ti-xs ti ti-lock me-1"></i> Security</a></li>
      </ul>
    </div>
    <el-card class="box-card">
      <!-- <h5 class="card-header">Profile Details</h5> -->
      <template v-if="tab == 1">
        <div class="card-body" style="margin-bottom:1rem;">
          <div class="d-flex align-items-start align-items-sm-center gap-4">
            <userAvatar :user="user" />
            <div class="button-wrapper">
              <div class="text-muted">Allowed JPG, GIF or PNG. Max size of 800K</div>
            </div>
          </div>
        </div>
        <hr class="my-0" />
        <el-form style="margin-top:1rem;">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item :label="$t('user.username')">
                <el-input v-model="user.userName" :readonly="true"></el-input>
              </el-form-item>
              <el-form-item :label="$t('user.phonenumber')">
                <el-input v-model="user.phonenumber" :readonly="true"></el-input>
              </el-form-item>
              <el-form-item :label="$t('user.useremail')">
                <el-input v-model="user.email" :readonly="true"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('user.dept')">
                <el-input :value="user.dept.deptName + ' / ' + postGroup" :readonly="true"></el-input>
              </el-form-item>
              <el-form-item :label="$t('user.role')">
                <el-input :value="roleGroup" :readonly="true"></el-input>
              </el-form-item>
              <el-form-item :label="$t('user.createtime')">
                <el-input v-model="user.createTime" :readonly="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>

        <userInfo :user="user" />
      </template>

      <resetPwd :user="user" v-show="tab == 2" />

    </el-card>
    
    <Footer :layout="layout"/>
    <el-row :gutter="20" v-if="false">
      <el-col :span="6" :xs="24">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>个人信息</span>
          </div>
          <div>
            <div class="text-center">
              <userAvatar :user="user" />
            </div>
            <ul class="list-group list-group-striped">
              <li class="list-group-item">
                <svg-icon icon-class="user" />用户名称
                <div class="pull-right">{{ user.userName }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="phone" />手机号码
                <div class="pull-right">{{ user.phonenumber }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="email" />用户邮箱
                <div class="pull-right">{{ user.email }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="tree" />所属部门
                <div class="pull-right" v-if="user.dept">{{ user.dept.deptName }} / {{ postGroup }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="peoples" />所属角色
                <div class="pull-right">{{ roleGroup }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="date" />创建日期
                <div class="pull-right">{{ user.createTime }}</div>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col :span="18" :xs="24">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>基本资料</span>
          </div>
          <el-tabs v-model="activeTab">
            <el-tab-pane label="基本资料" name="userinfo">
              <userInfo :user="user" />
            </el-tab-pane>
            <el-tab-pane label="修改密码" name="resetPwd">
              <resetPwd :user="user" />
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>

  </div>
</template>

<script>
import Footer from '../../../../components/Footer'
import userAvatar from "./userAvatar";
import userInfo from "./userInfo";
import resetPwd from "./resetPwd";
import { getUserProfile } from "@/api/system/user";

export default {
  name: "Profile",
  components: { userAvatar, userInfo, resetPwd, Footer },
  data() {
    return {
      tab: 1,
      user: { dept: {} },
      roleGroup: {},
      postGroup: {},
      activeTab: "userinfo"
    };
  },
  computed: {
    layout() {
      return localStorage.getItem('v-layout-content')||'container-xxl';
    }
  },
  created() {
    this.getUser();
  },
  methods: {
    getUser() {
      getUserProfile().then(response => {
        this.user = response.data;
        this.roleGroup = response.roleGroup;
        this.postGroup = response.postGroup;
      });
    }
  }
};
</script>
